
import 'package:flutter/material.dart';

class CustomLabelWidget extends StatelessWidget {
  final List<String>? list;
  final ValueChanged<int>? onTag;
  final double? fontSize;
  final Color? fontColor;
  final FontWeight? fontWeight;
  final EdgeInsetsGeometry? padding;
  final double? width;
  final double? height;

  const CustomLabelWidget(
      {super.key, this.list,
      this.onTag,
      this.fontSize,
      this.fontColor,
      this.fontWeight,
      this.padding,
      this.width,
      this.height});

  @override
  Widget build(BuildContext context) {
    var widgetList = <Widget>[];
    for (var i = 0; i < (list?.length ?? 0); i++) {
      var item = GestureDetector(
        child: Container(
            padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
            decoration:  BoxDecoration(
                borderRadius: BorderRadius.circular(4),
                color:const  Color(0xff262626).withOpacity(0.9),
            ),
            child: Text(
              list![i],
              maxLines: 1,
              style: TextStyle(
                fontSize: fontSize ?? 12,
                color: fontColor ?? const Color(0xff999999),
              ),
            )),
        onTap: () => onTag?.call(i),
      );
      widgetList.add(item);
    }
    return Padding(
      padding: padding ?? const EdgeInsets.all(0),
      child: SizedBox(
        width: width ?? 280,
        height: height ?? 24, // 最多1排
        child: Wrap(
          crossAxisAlignment:
              WrapCrossAlignment.center, //垂直居中 交叉轴（crossAxis）方向上的对齐方式。
          spacing: 10, // 主轴(水平)方向间距
          runSpacing: 4, // 纵轴（垂直）方向间距
          alignment: WrapAlignment.start,
          children: widgetList,
        ),
      ),
    );
  }
}
